package saucaca.fragment;

import java.util.List;

import saucaca.Adapter.TopicAdapter;
import saucaca.Object.HomeData;
import saucaca.Object.TopicObject;
import saucaca.Util.TagName;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.lemon.kenhnhacvn.MainActivity;
import com.lemon.kenhnhacvn.R;


public class TopicFragment extends Fragment {
	private GridView gridTopics;
	List<TopicObject> listToppic;
	private MainActivity mActivity = null;

	@SuppressLint("NewApi")
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//		mActivity.getActionBar().hide();
		View view = inflater.inflate(R.layout.topics, container, false);
		findViewById(view);
		listToppic =  HomeData.homeListTopics;//JsonReader.getHomelistTopics();
		gridTopics.setAdapter(new TopicAdapter(mActivity, listToppic));
		mActivity.myActionBar.setMenu(R.string.menu_chude, false, true);
		return view;
	}
	@Override
	public void onHiddenChanged(boolean hidden) {
		super.onHiddenChanged(hidden);
		if(!hidden)
			mActivity.myActionBar.setMenu(R.string.menu_chude, false, true);
	}
	public void findViewById(View view) {
		gridTopics = (GridView) view.findViewById(R.id.gridViewTopic);
		gridTopics.setOnItemClickListener(clickListener);
	}

	OnItemClickListener clickListener = new OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//			String data = listToppic.get(position).getCATE_CODE()+TagName.keyBundle+listToppic.get(position).getTXNAME();
			mActivity.switchContent(TopicDetailFragment.class.getName(), listToppic.get(position));
		}
	};

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		if (activity instanceof MainActivity) {
			mActivity = (MainActivity) activity;
		}
	}
	
}
